<template>
  <div class="consultation">
    <h2>个人中心</h2>
    <div class="consultation-block">
      <el-form ref="form" :model="userInfo" label-width="160px" size="mini">
        <el-form-item label="用户名">
          <el-input disabled v-model="userInfo.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="userInfo.password"></el-input>
        </el-form-item>
      </el-form>
      <div style="text-align: center;">
        <el-button style="margin: 0 auto;" size="mini" type="danger" @click="updateData">编辑</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { getSomeUser, updateUser } from "../service.js";
export default {
  name: "home",
  beforeCreate() {
    let userInfo = JSON.parse(localStorage.getItem("chartWebInfo"))
    getSomeUser({
      id: userInfo.id
    }).then(res => {
      this.userInfo = res.data.data[0]
      console.log(this.userInfo)
    })
  },
  data() {
    return {
      userInfo: {}
    };
  },
  methods: {
    updateData() {
      updateUser(this.userInfo.id, this.userInfo).then(res => {
        console.log(res)
        if (res.code === 200) {
          localStorage.setItem("chartWebInfo", JSON.stringify(res.data))
          this.$message.success('修改成功')
        }
      })
    },
  },
};
</script>

<style scoped>
h2 {
  text-align: center;
  margin-top: 20px;
  margin-bottom: 20px;
}
.consultation-block {
  width: 90%;
  margin-left: 5%;
}

.pagination {
  text-align: center;
  margin-top: 20px;
}
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}

.el-icon-circle-close {
  position: absolute;
  top: -5px;
  right: -5px;
  cursor: pointer;
  color: red;
}
</style>
